<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- 1、引入依赖 -->
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

  <div id="app"></div>

  <!-- 2、编写react代码 -->
  <script type="text/babel">

    class App extends React.Component {
      constructor(){
        super()
        this.state = {
          movies: ["大话西游", "孤注一掷", "超能一家人"]
        }
      }

      // 所有组件必须实现render方法
      render() {
        const { movies } = this.state

        let liArr = []
        for (const movie of movies) { //forof 拿到数组的每一项
          liArr.push(<li key={movie}>{movie}</li>)
        }

        // 必须用return返回
        return (
          // {}语法  里面可以是表达式
          <div>
            <h2>电影列表</h2>
            <div>使用forof循环</div>
            <ul>{liArr}</ul>
            
            <div>使用map</div>
            <ul>
              {
                movies.map((movie, index) => {
                  return <li key={index}>{movie}</li>
                })
              }
            </ul>
          </div>
        )
      }
    }


    ReactDOM.render(<App/>, document.getElementById('app')) 
  </script>
</body>
</html>